/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmMasterBarang.java
 *
 * Created on Jan 24, 2012, 1:54:03 PM
 */
package SIMRS.Apotek.view;

import SIMRS.Apotek.sql.KoneksiDatabase;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import usu.widget.Form;

/**
 *
 * @author Maulida
 */
public class frmMasterBarang extends Form {
    Connection koneksi=KoneksiDatabase.getKoneksi();
    private static DefaultTableModel model;
   
    /** Creates new form frmMasterBarang */
    public frmMasterBarang() {
        initComponents();
        
        model=new DefaultTableModel();
        tblMasterBarang.setModel(model);
        model.addColumn("Kode Barang");
        model.addColumn("Nama Barang");
        model.addColumn("Golongan Barang");
        model.addColumn("Jenis Barang");
        model.addColumn("Satuan Besar");
        model.addColumn("Satuan Kecil");
        model.addColumn("Jumlah Kemasan");
        model.addColumn("Jumlah Barang Terkecil");
        model.addColumn("Harga Netto 1");
        model.addColumn("Harga Netto 2");
        model.addColumn("Jumlah Stok");
      
        loadDataMasterBarang();
        
        txtKodeBarang.setEnabled(false);
        txtNamaBarang.setEnabled(false);
        cmbGolonganBarang.setEnabled(false);
        cmbJenisBarang.setEnabled(false);
        cmbSatuanBesar.setEnabled(false);
        cmbSatuanKecil.setEnabled(false);
        txtJumlahKemasan.setEnabled(false);
        txtJumlahBarangTerkecil.setEnabled(false);
        txtapotekRuang.setEnabled(false);
        golbar.setEnabled(false);
        jenbar.setEnabled(false);
        satbes.setEnabled(false);
        satkec.setEnabled(false);
        
        
        cmbGolonganBarang.addItem("");
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select * from golonganbarang order by KdGolonganBarang asc");
         rs.beforeFirst();
         while(rs.next()){
             cmbGolonganBarang.addItem(rs.getString("GolonganBarang"));
         }
         rs.close();
     }
     catch(SQLException ex)
     {
         System.out.println("Error : "+ex);
         }
        
        
        cmbJenisBarang.addItem("");
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select * from jenisbarang order by KdJenisBarang asc");
         rs.beforeFirst();
         while(rs.next()){
             cmbJenisBarang.addItem(rs.getString("JenisBarang"));
         }
         rs.close();
     }
     catch(SQLException ex)
     {
         System.out.println("Error : "+ex);
         }
        
        cmbSatuanBesar.addItem("");
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select * from satuanbesar order by KdSatuanBesar asc");
         rs.beforeFirst();
         while(rs.next()){
             cmbSatuanBesar.addItem(rs.getString("SatuanBesar"));
         }
         rs.close();
     }
     catch(SQLException ex)
     {
         System.out.println("Error : "+ex);
         }
        
        cmbSatuanKecil.addItem("");
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select * from satuankecil order by KdSatuanKecil asc");
         rs.beforeFirst();
         while(rs.next()){
             cmbSatuanKecil.addItem(rs.getString("SatuanKecil"));
         }
         rs.close();
     }
     catch(SQLException ex)
     {
         System.out.println("Error : "+ex);
         }

        
        setIconImage(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/icon.png")).getImage());
        setTitle(".:: Form Master Barang ::.");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlForm1 = new SIMRS.Apotek.widget.PnlForm();
        label8 = new SIMRS.Apotek.widget.Label();
        txtJumlahKemasan = new SIMRS.Apotek.widget.TextBox();
        scrollPane1 = new SIMRS.Apotek.widget.ScrollPane();
        tblMasterBarang = new SIMRS.Apotek.widget.Table();
        btnCetak = new SIMRS.Apotek.widget.button2();
        btnUbah = new SIMRS.Apotek.widget.button2();
        btnHapus = new SIMRS.Apotek.widget.button2();
        btnTutup = new SIMRS.Apotek.widget.button2();
        label13 = new SIMRS.Apotek.widget.Label();
        btnSimpan = new SIMRS.Apotek.widget.button2();
        jPanel1 = new javax.swing.JPanel();
        label2 = new SIMRS.Apotek.widget.Label();
        txtKodeBarang = new SIMRS.Apotek.widget.TextBox();
        label3 = new SIMRS.Apotek.widget.Label();
        txtNamaBarang = new SIMRS.Apotek.widget.TextBox();
        label4 = new SIMRS.Apotek.widget.Label();
        cmbGolonganBarang = new javax.swing.JComboBox();
        label5 = new SIMRS.Apotek.widget.Label();
        cmbJenisBarang = new javax.swing.JComboBox();
        label6 = new SIMRS.Apotek.widget.Label();
        cmbSatuanBesar = new javax.swing.JComboBox();
        label7 = new SIMRS.Apotek.widget.Label();
        cmbSatuanKecil = new javax.swing.JComboBox();
        golbar = new javax.swing.JTextField();
        satbes = new javax.swing.JTextField();
        satkec = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        label11 = new SIMRS.Apotek.widget.Label();
        txtHargaNetto2 = new SIMRS.Apotek.widget.TextBox();
        label10 = new SIMRS.Apotek.widget.Label();
        txtHargaNetto1 = new SIMRS.Apotek.widget.TextBox();
        label12 = new SIMRS.Apotek.widget.Label();
        txtJumlahStok = new SIMRS.Apotek.widget.TextBox();
        label9 = new SIMRS.Apotek.widget.Label();
        txtJumlahBarangTerkecil = new SIMRS.Apotek.widget.TextBox();
        label1 = new SIMRS.Apotek.widget.Label();
        txtapotekRuang = new SIMRS.Apotek.widget.TextBox();
        btnTutup2 = new SIMRS.Apotek.widget.button2();
        jenbar = new javax.swing.JTextField();

        setTitle("Form Master Barang");
        setAnimationHide(usu.widget.constan.Animation.SHOW_FROM_BOTTOM);
        setAnimationShow(usu.widget.constan.Animation.SHOW_FROM_TOP);
        setUndecorated(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        pnlForm1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(57, 190, 53), 3, true));
        pnlForm1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        label8.setText("Jumlah Kemasan");
        pnlForm1.add(label8, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 160, 104, -1));
        pnlForm1.add(txtJumlahKemasan, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 160, 105, -1));

        tblMasterBarang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblMasterBarang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblMasterBarangMouseClicked(evt);
            }
        });
        scrollPane1.setViewportView(tblMasterBarang);

        pnlForm1.add(scrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 380, 740, 190));

        btnCetak.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_cetak.png"))); // NOI18N
        btnCetak.setText("Cetak");
        pnlForm1.add(btnCetak, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 590, -1, -1));

        btnUbah.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_edit.png"))); // NOI18N
        btnUbah.setText("Ubah");
        btnUbah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUbahActionPerformed(evt);
            }
        });
        pnlForm1.add(btnUbah, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 590, -1, -1));

        btnHapus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_hapus.png"))); // NOI18N
        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });
        pnlForm1.add(btnHapus, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 590, -1, -1));

        btnTutup.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_close.png"))); // NOI18N
        btnTutup.setText("Tutup");
        btnTutup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTutupActionPerformed(evt);
            }
        });
        pnlForm1.add(btnTutup, new org.netbeans.lib.awtextra.AbsoluteConstraints(870, 560, -1, -1));

        label13.setForeground(new java.awt.Color(255, 255, 255));
        label13.setText("Data Master Barang");
        label13.setFont(new java.awt.Font("Tahoma", 1, 18));
        pnlForm1.add(label13, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 400, -1));

        btnSimpan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_simpan.png"))); // NOI18N
        btnSimpan.setText("Tambah");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });
        pnlForm1.add(btnSimpan, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 590, -1, -1));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setOpaque(false);

        label2.setText("Kode Barang");

        label3.setText("Nama Barang");

        label4.setText("Golongan Barang");

        cmbGolonganBarang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbGolonganBarangActionPerformed(evt);
            }
        });

        label5.setText("Jenis Barang");

        cmbJenisBarang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbJenisBarangActionPerformed(evt);
            }
        });

        label6.setText("Satuan Besar");

        cmbSatuanBesar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbSatuanBesarActionPerformed(evt);
            }
        });

        label7.setText("Satuan Kecil");

        cmbSatuanKecil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbSatuanKecilActionPerformed(evt);
            }
        });

        golbar.setForeground(new java.awt.Color(255, 255, 51));
        golbar.setBorder(null);
        golbar.setOpaque(false);

        satbes.setForeground(new java.awt.Color(255, 255, 0));
        satbes.setBorder(null);
        satbes.setOpaque(false);

        satkec.setForeground(new java.awt.Color(255, 255, 0));
        satkec.setBorder(null);
        satkec.setOpaque(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(89, 89, 89)
                        .addComponent(txtKodeBarang, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(74, 74, 74)
                        .addComponent(txtNamaBarang, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(55, 55, 55)
                        .addComponent(cmbGolonganBarang, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(golbar, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(80, 80, 80)
                        .addComponent(cmbJenisBarang, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(75, 75, 75)
                        .addComponent(cmbSatuanBesar, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(satbes, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(67, 67, 67)
                        .addComponent(cmbSatuanKecil, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(satkec, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtKodeBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtNamaBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cmbGolonganBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(golbar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbJenisBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cmbSatuanBesar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(satbes, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cmbSatuanKecil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(satkec, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        pnlForm1.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, 360, 220));

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setOpaque(false);

        label11.setText("Harga Netto 2");

        label10.setText("Harga Netto 1");

        label12.setText("Jumlah Stok");

        label9.setText("Jumlah Barang Terkecil");

        label1.setText("Ruangan");

        txtapotekRuang.setText("Apotek");
        txtapotekRuang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtapotekRuangActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(label10, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(63, 63, 63)
                            .addComponent(txtHargaNetto1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(label12, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(72, 72, 72)
                            .addComponent(txtJumlahStok, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(72, 72, 72)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtapotekRuang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtHargaNetto2, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))))
                .addGap(21, 21, 21))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label9, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtJumlahBarangTerkecil, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(46, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtJumlahBarangTerkecil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label12, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtJumlahStok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label10, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtHargaNetto1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label11, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtHargaNetto2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtapotekRuang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pnlForm1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 150, 300, 220));

        btnTutup2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_close.png"))); // NOI18N
        btnTutup2.setText("Tutup");
        btnTutup2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTutup2ActionPerformed(evt);
            }
        });
        pnlForm1.add(btnTutup2, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 590, 100, 30));

        jenbar.setForeground(new java.awt.Color(255, 255, 0));
        jenbar.setBorder(null);
        jenbar.setOpaque(false);
        pnlForm1.add(jenbar, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 260, 60, -1));

        getContentPane().add(pnlForm1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 770, 640));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-768)/2, (screenSize.height-641)/2, 768, 641);
    }// </editor-fold>//GEN-END:initComponents

    
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
    System.exit(1);
}//GEN-LAST:event_formWindowClosing

private void btnTutupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTutupActionPerformed
    dispose();
}//GEN-LAST:event_btnTutupActionPerformed

private void btnTutup2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTutup2ActionPerformed
// TODO add your handling code here:
    dispose();
}//GEN-LAST:event_btnTutup2ActionPerformed

    private void tblMasterBarangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblMasterBarangMouseClicked
        // TODO add your handling code here:
        int i = tblMasterBarang.getSelectedRow();
        txtKodeBarang.setText(model.getValueAt(i, 0).toString());
        txtNamaBarang.setText(model.getValueAt(i, 1).toString());
        cmbGolonganBarang.setSelectedItem(model.getValueAt(i, 2).toString());
        cmbJenisBarang.setSelectedItem(model.getValueAt(i, 3).toString());
        cmbSatuanBesar.setSelectedItem(model.getValueAt(i, 4).toString());
        cmbSatuanKecil.setSelectedItem(model.getValueAt(i, 5).toString());
        txtJumlahKemasan.setText(model.getValueAt(i, 6).toString());   
        txtJumlahBarangTerkecil.setText(model.getValueAt(i, 7).toString());  
   
        txtHargaNetto1.setText(model.getValueAt(i, 8).toString());  
        txtHargaNetto2.setText(model.getValueAt(i, 9).toString());
        txtJumlahStok.setText(model.getValueAt(i, 10).toString()); 
    }//GEN-LAST:event_tblMasterBarangMouseClicked

    private void enableTambah(boolean v){
        //buat hidupin
            txtKodeBarang.setEnabled(v);
            txtNamaBarang.setEnabled(v);
            cmbGolonganBarang.setEnabled(v);
            cmbJenisBarang.setEnabled(v);
            cmbSatuanBesar.setEnabled(v);
            cmbSatuanKecil.setEnabled(v);
            txtJumlahKemasan.setEnabled(v);
            txtJumlahBarangTerkecil.setEnabled(v);
            txtJumlahStok.setEnabled(v);
            txtJumlahKemasan.setEnabled(v);
            txtJumlahBarangTerkecil.setEnabled(v);
            txtHargaNetto1.setEnabled(v);
            txtHargaNetto2.setEnabled(v);
            golbar.setEnabled(v);
            jenbar.setEnabled(v);
            satbes.setEnabled(v);
            satkec.setEnabled(v);
    }
    
    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimpanActionPerformed
        // TODO add your handling code here:
        if(btnSimpan.getLabel().equals("Tambah")){
            btnSimpan.setLabel("Simpan");
            enableTambah(true);
            tblMasterBarangMouseClicked(null);
        }
        else if(btnSimpan.getLabel().equals("Simpan")){
            Connection c=KoneksiDatabase.getKoneksi();
            try {
                CallableStatement exectInsert=c.prepareCall("{call InsertMasterBarang(?,?,?,?,?,?,?,?,?,?,?,?)}");
                exectInsert.setString(1, txtKodeBarang.getText());
                exectInsert.setString(2, txtNamaBarang.getText());
                exectInsert.setString(3, golbar.getText());
                exectInsert.setString(4, jenbar.getText());
                exectInsert.setString(5, satbes.getText());
                exectInsert.setString(6, satkec.getText());
                exectInsert.setInt(7, Integer.parseInt(txtJumlahKemasan.getText()));
                exectInsert.setInt(8, Integer.parseInt(txtJumlahBarangTerkecil.getText()));
                exectInsert.setInt(9, Integer.parseInt(txtHargaNetto1.getText()));
                exectInsert.setInt(10, Integer.parseInt(txtHargaNetto2.getText()));
                exectInsert.setString(11, "R11");
                exectInsert.setInt(12, Integer.parseInt(txtJumlahStok.getText()));
                
                ResultSet rs=exectInsert.executeQuery();
                loadDataMasterBarang();
                
                JOptionPane.showMessageDialog(this, "Data Berhasil Disimpan");
                btnSimpan.setLabel("Tambah");
            enableTambah(false);
            txtNamaBarang.setText("");
            txtKodeBarang.setText("");
            txtJumlahKemasan.setText("");
            txtJumlahBarangTerkecil.setText("");
            txtJumlahStok.setText("");
            txtJumlahKemasan.setText("");
            txtJumlahBarangTerkecil.setText("");
            txtHargaNetto1.setText("");
            txtHargaNetto2.setText("");
            golbar.setText("");
            jenbar.setText("");
            satbes.setText("");
            satkec.setText("");
               
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(this, "Data gagal disimpan");
            }
        }
    }//GEN-LAST:event_btnSimpanActionPerformed

    //buat konversi data ke kode
    private void cmbGolonganBarangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbGolonganBarangActionPerformed
        // TODO add your handling code here:
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select KdGolonganBarang from golonganbarang where golonganbarang= '"+cmbGolonganBarang.getSelectedItem().toString()+"'");
         rs.beforeFirst();
         while(rs.next()){
             golbar.setText(rs.getString(1).trim());
         }
         rs.close();
         }
         catch(SQLException ex)
         {
             System.out.println("Error : "+ex);
             }
    }//GEN-LAST:event_cmbGolonganBarangActionPerformed

    private void cmbJenisBarangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbJenisBarangActionPerformed
        // TODO add your handling code here:
         try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select KdJenisBarang from jenisbarang where jenisbarang= '"+cmbJenisBarang.getSelectedItem().toString()+"'");
         rs.beforeFirst();
         while(rs.next()){
             jenbar.setText(rs.getString(1).trim());
         }
         rs.close();
         }
         catch(SQLException ex)
         {
             System.out.println("Error : "+ex);
             }
        
    }//GEN-LAST:event_cmbJenisBarangActionPerformed

    private void cmbSatuanBesarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbSatuanBesarActionPerformed
        // TODO add your handling code here:
         try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select KdSatuanBesar from satuanbesar where satuanbesar= '"+cmbSatuanBesar.getSelectedItem().toString()+"'");
         rs.beforeFirst();
         while(rs.next()){
             satbes.setText(rs.getString(1).trim());
         }
         rs.close();
         }
         catch(SQLException ex)
         {
             System.out.println("Error : "+ex);
             }
    }//GEN-LAST:event_cmbSatuanBesarActionPerformed

    private void cmbSatuanKecilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbSatuanKecilActionPerformed
        // TODO add your handling code here:
         try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select KdSatuanKecil from satuankecil where satuankecil= '"+cmbSatuanKecil.getSelectedItem().toString()+"'");
         rs.beforeFirst();
         while(rs.next()){
             satkec.setText(rs.getString(1).trim());
         }
         rs.close();
         }
         catch(SQLException ex)
         {
             System.out.println("Error : "+ex);
             }
    }//GEN-LAST:event_cmbSatuanKecilActionPerformed

    private void txtapotekRuangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtapotekRuangActionPerformed
        // TODO add your handling code here:
        txtapotekRuang.setText("R11"); //R11==APOTEK
    }//GEN-LAST:event_txtapotekRuangActionPerformed

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHapusActionPerformed
        // TODO add your handling code here:
        Connection c=KoneksiDatabase.getKoneksi();
        try {
            CallableStatement exectInsert=c.prepareCall("{call DeleteMasterBarang(?,?,?,?,?,?,?,?,?,?,?,?)}");
                exectInsert.setString(1, txtKodeBarang.getText());
                exectInsert.setString(2, txtNamaBarang.getText());
                exectInsert.setString(3, golbar.getText());
                exectInsert.setString(4, jenbar.getText());
                exectInsert.setString(5, satbes.getText());
                exectInsert.setString(6, satkec.getText());
                exectInsert.setInt(7, Integer.parseInt(txtJumlahKemasan.getText()));
                exectInsert.setInt(8, Integer.parseInt(txtJumlahBarangTerkecil.getText()));
                exectInsert.setInt(9, Integer.parseInt(txtHargaNetto1.getText()));
                exectInsert.setInt(10, Integer.parseInt(txtHargaNetto2.getText()));
                exectInsert.setString(11, "R11");
                exectInsert.setInt(12, Integer.parseInt(txtJumlahStok.getText()));
                
                ResultSet rs=exectInsert.executeQuery();
                loadDataMasterBarang();
            
            JOptionPane.showMessageDialog(this, "Satu data berhasil dihapus");
        } catch (SQLException ex) {
           JOptionPane.showMessageDialog(this, "Gagal menghapus data");
        }
    }//GEN-LAST:event_btnHapusActionPerformed

    private void btnUbahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUbahActionPerformed
        // TODO add your handling code here:
         if(btnUbah.getLabel().equals("Ubah")){
      /*       cmbGolonganBarang.setEnabled(true);
             cmbJenisBarang.setEnabled(true);
             cmbSatuanBesar.setEnabled(true);
             cmbSatuanKecil.setEnabled(true);*/
            enableTambah(true); 
             
            btnUbah.setLabel("Simpan");
            tblMasterBarangMouseClicked(null);
        } else if(btnUbah.getLabel().equals("Simpan")){
            Connection c=KoneksiDatabase.getKoneksi();
            try {
                CallableStatement updateMb=c.prepareCall("{call UpdateMasterBarang(?,?,?,?,?,?,?,?,?,?,?,?)}");
                updateMb.setString(1, txtKodeBarang.getText());
                updateMb.setString(2, txtNamaBarang.getText());
                updateMb.setString(3, golbar.getText());
                updateMb.setString(4, jenbar.getText());
                updateMb.setString(5, satbes.getText());
                updateMb.setString(6, satkec.getText());
                updateMb.setInt(7, Integer.parseInt(txtJumlahKemasan.getText()));
                updateMb.setInt(8, Integer.parseInt(txtJumlahBarangTerkecil.getText()));
                updateMb.setInt(9, Integer.parseInt(txtHargaNetto1.getText()));
                updateMb.setInt(10, Integer.parseInt(txtHargaNetto2.getText()));
                updateMb.setString(11, "R11");
                updateMb.setInt(12, Integer.parseInt(txtJumlahStok.getText()));
                
                ResultSet rs=updateMb.executeQuery();
                loadDataMasterBarang();
                
                JOptionPane.showMessageDialog(this, "Data sudah diupdate");
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(this, "Data gagal diupdate");
            }
        }
    }//GEN-LAST:event_btnUbahActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private SIMRS.Apotek.widget.button2 btnCetak;
    private SIMRS.Apotek.widget.button2 btnHapus;
    private SIMRS.Apotek.widget.button2 btnSimpan;
    private SIMRS.Apotek.widget.button2 btnTutup;
    private SIMRS.Apotek.widget.button2 btnTutup2;
    private SIMRS.Apotek.widget.button2 btnUbah;
    private javax.swing.JComboBox cmbGolonganBarang;
    private javax.swing.JComboBox cmbJenisBarang;
    private javax.swing.JComboBox cmbSatuanBesar;
    private javax.swing.JComboBox cmbSatuanKecil;
    private javax.swing.JTextField golbar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jenbar;
    private SIMRS.Apotek.widget.Label label1;
    private SIMRS.Apotek.widget.Label label10;
    private SIMRS.Apotek.widget.Label label11;
    private SIMRS.Apotek.widget.Label label12;
    private SIMRS.Apotek.widget.Label label13;
    private SIMRS.Apotek.widget.Label label2;
    private SIMRS.Apotek.widget.Label label3;
    private SIMRS.Apotek.widget.Label label4;
    private SIMRS.Apotek.widget.Label label5;
    private SIMRS.Apotek.widget.Label label6;
    private SIMRS.Apotek.widget.Label label7;
    private SIMRS.Apotek.widget.Label label8;
    private SIMRS.Apotek.widget.Label label9;
    private SIMRS.Apotek.widget.PnlForm pnlForm1;
    private javax.swing.JTextField satbes;
    private javax.swing.JTextField satkec;
    private SIMRS.Apotek.widget.ScrollPane scrollPane1;
    private SIMRS.Apotek.widget.Table tblMasterBarang;
    private SIMRS.Apotek.widget.TextBox txtHargaNetto1;
    private SIMRS.Apotek.widget.TextBox txtHargaNetto2;
    private SIMRS.Apotek.widget.TextBox txtJumlahBarangTerkecil;
    private SIMRS.Apotek.widget.TextBox txtJumlahKemasan;
    private SIMRS.Apotek.widget.TextBox txtJumlahStok;
    private SIMRS.Apotek.widget.TextBox txtKodeBarang;
    private SIMRS.Apotek.widget.TextBox txtNamaBarang;
    private SIMRS.Apotek.widget.TextBox txtapotekRuang;
    // End of variables declaration//GEN-END:variables

    private void loadDataMasterBarang() {
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        Connection c=KoneksiDatabase.getKoneksi();
        try {
            Statement s=c.createStatement();
             String sql = "(SELECT obat.KdBarang,obat.NamaBarang, golonganbarang.GolonganBarang, jenisbarang.JenisBarang,satuanbesar.SatuanBesar,satuankecil.SatuanKecil,obat.JmlKemasan,obat.JmlKeluarTerkecil, stok.JmlStok,hargabarangmedis.HargaNetto1, hargabarangmedis.HargaNetto2 FROM obat INNER JOIN golonganbarang ON (obat.KdGolonganBarang=golonganbarang.KdGolonganBarang) INNER JOIN jenisbarang ON (obat.KdJenisBarang=jenisbarang.KdJenisBarang) INNER JOIN satuanbesar ON (obat.KdSatuanBesar=satuanbesar.KdSatuanBesar) INNER JOIN satuankecil ON (obat.KdSatuanKecil=satuankecil.KdSatuanKecil)INNER JOIN stok ON (obat.KdBarang=stok.KdBarang)INNER JOIN hargabarangmedis ON (obat.KdBarang=hargabarangmedis.KdBarang))";
            ResultSet rs= s.executeQuery(sql);
            
            while (rs.next()){
                Object[] o = new Object[11];
                o[0]=rs.getString("KdBarang");
                o[1]=rs.getString("NamaBarang"); 
                o[2]=rs.getString("GolonganBarang");
                o[3]=rs.getString("JenisBarang");
                o[4]=rs.getString("SatuanBesar");
                o[5]=rs.getString("SatuanKecil");
                o[6]=rs.getInt("JmlKemasan");
                o[7]=rs.getInt("JmlKeluarTerkecil");
                o[8]=rs.getInt("JmlStok");
                o[9]=rs.getInt("HargaNetto1");
                o[10]=rs.getInt("HargaNetto2");
                
                model.addRow(o);
                
                
             }
            rs.close();
            s.close();
        } catch (SQLException ex) {
            
        }
        
    }
}
